/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */

package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class AddressCtr
{
    private AddressBook addrBook;

    /**
     * Constructor for objects of class AddressCtr
     */
    public AddressCtr()
    {
        addrBook = AddressBook.getInstance();
    }
    
    /**
     * Finds the the entry in array via the persons phonenumber.
     * 
     * @param phone persons phonenumber to be used in search.
     */
    public Person getPerson(String phone)
    {   
        Person person = addrBook.findPerson(phone);
        return person;
    }
    
    /**
     * Creating a new entry in the address book.
     * 
     * @param name sets the name for the entry
     * @param address sets the address for the enty
     * @param postalCode sets the postal code for the entry
     * @param city sets the city for the entry
     * @param phone sets the phonenumber for the entry
     */
    public void createPerson(String name, String address, String postalCode, String city, String phone)
    {   
       Person personObj = new Person(name, address, postalCode, city, phone);
       addrBook.addPerson(personObj);
    }
    
    /**
     * Deleting a person with the use of there phonenumber.
     * 
     * @param phone the persons phonenumber to be used in deleting there information
     */
    public boolean deletePerson(String phone)
    {
        return addrBook.deletePerson(phone);
    }
    
    /**
     * Editing personal information.
     * 
     * @param choise selecting wich part to edit
     * @param newData the data to replace in array
     */
    public void editPersonData(Person person, int choice, String newData)
    {
        if (choice == 1)
        {
            person.setName(newData);
        } 
        else if (choice == 2)
        {
            person.setAddress(newData);
        }
        else if (choice == 3)
        {
            person.setPostalCode(newData);
        }
        else if (choice == 4)
        {
            person.setCity(newData);
        }
        else if (choice == 5)
        {
            person.setPhone(newData);
        }
    }
    
    /**
     * Lists all persons in array.
     */
    public ArrayList<Person> listAllPersons()
    {
        return addrBook.listAllPersons();
    }  
}
